////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// This file is a part of PMCG project. PMCG is the acronym of Physical       //
// Methods in Computer Graphics.                                              //
//                                                                            //
// Classical algorithms in computer graphics use discrete objects in 3D space //
// like vectors, matrices, triangles, planes. Physical way use an  analytical //
// objects like function, scalar and vector fields. Physical way gives new    //
// look to classical algorithms and allows to overcome some difficulties of   //
// pure geometric methods.                                                    //
//                                                                            //
// Project site:                                                              //
//     http://code.google.com/p/pmcg/                                         //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

#include <cmath>

#include "Vector3D.h"

Vector3D::Vector3D()
{
}

Vector3D::Vector3D(double x, double y, double z)
    : m_x(x), m_y(y), m_z(z)
{
}

Vector3D::~Vector3D()
{
}

void Vector3D::Normalize()
{
    double l = sqrt(m_x * m_x + m_y * m_y + m_z * m_z);
    m_x /= l;
    m_y /= l;
    m_z /= l;
}

const Vector3D operator+ (const Vector3D & a, const Vector3D & b)
{
    return Vector3D (a.m_x + b.m_x, a.m_y + b.m_y, a.m_z + b.m_z);
}

const Vector3D operator- (const Vector3D & a, const Vector3D & b)
{
    return Vector3D (a.m_x - b.m_x, a.m_y - b.m_y, a.m_z - b.m_z);
}

double operator* (const Vector3D & a, const Vector3D & b)
{
    return a.m_x * b.m_x + a.m_y * b.m_y + a.m_z * b.m_z;
}

const Vector3D operator^ (const Vector3D & a, const Vector3D & b)
{
    return Vector3D (a.m_y * b.m_z - a.m_z * b.m_y,
                     a.m_z * b.m_x - a.m_x * b.m_z,
                     a.m_x * b.m_y - a.m_y * b.m_x);
}

const Vector3D operator/ (const Vector3D & a, double alpha)
{
    return Vector3D(a.m_x / alpha, a.m_y / alpha, a.m_z / alpha);
}
